from logging import exception
from conans import ConanFile, CMake, tools, AutoToolsBuildEnvironment
from conans import tools
import sys
import os
sys.path.append(os.environ.get('PYTHONPATH'))
from pathlib import Path
import shutil

class WebsocketppConan(ConanFile):
    name = "websocketpp"
    version = "master"
    url = "https://github.com/zaphoyd/websocketpp.git"
    description = "websocket "
    topics = ("<Put some tag here>", "<here>", "<and here>")
    settings = "os", "compiler", "build_type", "arch"
    options = {"shared": [True, False]}
    default_options = {"shared": False}
    generators = "cmake"
    
    def source(self):
        my_file = Path("pkgsrc")
        if my_file.exists():
            print("not need to update source")
        else:
            git = tools.Git(folder= "pkgsrc", verify_ssl=False)
            git.clone(self.url)

    def build(self):
        env_vars = tools.vcvars_dict(self)
        with tools.environment_append(env_vars):       
            self.run("mkdir build",cwd="pkgsrc")
            self.run("cmake   ..",cwd="pkgsrc/build")
            if(self.settings.build_type == "Debug"):
                self.run("MSBuild INSTALL.vcxproj   /m /p:Configuration=Debug", cwd="pkgsrc/build")
            if(self.settings.build_type == "Release"):
                    self.run("MSBuild INSTALL.vcxproj    /m /p:Configuration=Release",cwd="pkgsrc/build")

    def requirements(self):
        self.requires("boost/1.7.7")
    
    def package(self):
        if tools.os_info.is_windows:
            self.copy("pkgsrc\\install\\include\\*", dst="include\\", keep_path=True)

    def package_info(self):
        self.cpp_info.builddirs.append("")

        

